import 'package:flutter/material.dart';
import 'package:hktk_app/ienum/practice/ct_enum.dart';
import 'package:hktk_app/ienum/subject/chapter_icon_enum.dart';
import 'package:hktk_app/ienum/subject/collection_type_enum.dart';
import 'package:hktk_app/model/subject/chapter_model.dart';
// import 'package:hktk_app/pages/question/chapter_question_page.dart';

// import 'package:hktk_app/util/view_util.dart';
import 'package:hktk_app/widget/subject/chapter_show_widget.dart';

/// 章节叶子节点组件
class ChapterLeafWidget extends StatelessWidget {
  /// 章节相关数据
  final ChapterModel chapter;

  /// 栏目id
  final String columnId;

  /// 免费标志，true：免费/购买，false：未购买
  final bool free;

  /// 直接显示，不是在可展开组件里面显示，true：直接显示，false：在展开组件里面
  final bool directShow;

  /// 显示两个组件之间的间距，true：显示间距（底部间隔），false：不显示
  final bool spacingShow;

  const ChapterLeafWidget({
    super.key,
    required this.chapter,
    required this.columnId,
    required this.free,
    this.directShow = false,
    this.spacingShow = false,
  });

  @override
  Widget build(BuildContext context) {
    debugPrint("chapterLeafWidget 组件 -> build 方法执行 ===> ${chapter.name}");
    debugPrint("");
    return Padding(
      padding: EdgeInsets.only(bottom: spacingShow ? 20 : 0),
      // child:Text("111111"),
      child: ChapterShowWidget(
        title: chapter.name ?? "",
        iconEnum: free ? ChapterIconEnum.chapter : ChapterIconEnum.lock,
        directShow: directShow,
        onTapFun: _onTapFun,
        total: chapter.qcount ?? 1,
        num: chapter.ztNum ?? 0,
        showQuestion: true,
      ),
    );
  }

  /// 点击方法
  void _onTapFun(BuildContext context) {
    if (free) {
      // 跳转做题页面
      Navigator.pushNamed(context, "/chapter-question",arguments: {
        "id": chapter.id!,
        "collType": CollectionTypeEnum.chapter,
        "columnId": columnId,
        "cId": chapter.id!,
        "rType": CtEnum.chapter,
      });
    }
  }
}
